const loginChildren = [
    {
        path: '/security/login',
        name: 'login',
        component: () => import('@/views/security/login.vue')
    },
    {
        path: '/security/loginByMail',
        name: 'loginByMail',
        component: () => import('@/views/security/loginByMail.vue')
    }
];

const adminChild = [
    {
        path: '/admin/role',
        name: 'role',
        component: () => import('@/views/admin/role.vue')
    },
    {
        path: '/admin/user',
        name: 'user',
        component: () => import('@/views/admin/user.vue')
    },  
];

const checkerChild = [
    {
        path: '/checker/mark',
        name: 'mark',
        component: () => import('@/views/checker/mark.vue')
    },  
    {
        path: '/checker/examine',
        name: 'examine',
        component: () => import('@/views/checker/examine.vue')
    }, 
];

const demanderChild = [
    {
        path: '/demander/mainpage',
        name: 'mainpage',
        component: () => import('@/views/demander/mainpage.vue')
    },  
    {
        path: '/demander/submit',
        name: 'submit',
        component: () => import('@/views/demander/submit.vue')
    },  
    {
        path: '/demander/editquestion',
        name: 'editquestion',
        component: () => import('@/views/demander/editquestion.vue')
    }, 
];

const respondentChild = [
    {
        path: '/respondent/convert',
        name: 'convert',
        component: () => import('@/views/respondent/convert.vue')
    },  
    {
        path: '/respondent/personpage',
        name: 'personpage',
        component: () => import('@/views/respondent/personpage.vue')
    },  
];

const routes = [

    //访问路由“/”,自动重定向到"/home"
    {
        path: '/',
        redirect: '/security/loginHome'
    },
    {
        path: '/security/loginHome',
        name: 'loginHome',
        component: () => import('@/views/security/loginHome.vue'),
        children:loginChildren
    },
    {
        path: '/answer/answer',
        name: 'answer',
        component: () => import('@/views/answer/answer.vue'),
    },
    {
        path: '/answer/answerCheck',
        name: 'answerCheck',
        component: () => import('@/views/answer/answerCheck.vue'),
    },
    {
        path: '/404',
        name: "NotFound",
        component: () => import('@/views/404.vue')
    },
    {
        path: '/admin/adminHome',
        name: 'adminHome',
        component: () => import('@/views/admin/adminHome.vue'),
        children:adminChild
    },
    {
        path: '/demander/demanderHome',
        name: 'demanderHome',
        component: () => import('@/views/demander/demanderHome.vue'),
        children:demanderChild
    },
    {
        path: '/checker/checkerHome',
        name: 'checkerHome',
        component: () => import('@/views/checker/checkerHome.vue'),
        children:checkerChild
    },
    {
        path: '/respondent/respondentHome',
        name: 'respondentHome',
        component: () => import('@/views/respondent/respondentHome.vue'),
        children:respondentChild
    },
    {
        path: '/problems/management',
        name: "management",
        component: () => import('@/views/problems/management.vue')
    },
    {
        path: '/security/register',
        name: "register",
        component: () => import('@/views/security/register.vue')
    },
    {
        path: '/security/updateInfo',
        name: "updateInfo",
        component: () => import('@/views/security/updateInfo.vue')
    },
    {
        path: '/security/updatepassword',
        name: "updatepassword",
        component: () => import('@/views/security/updatepassword.vue')
    },
    {
        path: '/security/registeMail',
        name: "registeMail",
        component: () => import('@/views/security/registeMail.vue')
    },
    {
        path: '/security/forgetPwd',
        name: "forgetPwd",
        component: () => import('@/views/security/forgetPwd.vue')
    },
];

export const existsRoute = (path) => {
    for (let i = 0; i < routes.length; i++) {
        const r = routes[i];
        if (r.path == path) {
            return true;
        }
        if (r.children && r.children.length) {
            for (let k = 0; k < r.children.length; k++) {
                const sr = r.children[k];
                if (sr.path == path) {
                    return true;
                }
            }
        }
    }
    return false;
};

export default routes;